﻿@using KaytechSoftware.Cms.App.Common
@using KaytechSoftware.Cms.Common.Helpers
@model KaytechSoftware.Cms.App.Areas.Admin.Models.Base.GridEntityModel
@{
    ViewBag.Title = "Details";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

@{ var details = Model.GetDetails();}
@if (details != null)
{
    <h2>@string.Format("{0} details", Model.ControllerName)</h2>
    using (Html.BeginForm("Save", Model.ControllerName, FormMethod.Post, new { enctype = "multipart/form-data" }))
    {
         <div class="form">
             @Html.Hidden("ControllerName", Model.ControllerName)
             @foreach (var descriptor in details.FieldDescriptors)
             {
                 switch (descriptor.Renderer)
                 {
                     case RendererType.Hidden:
                         <div class="form-row">
                             @Html.Hidden(descriptor.Name, descriptor.TextValue)
                         </div>
                         <div class="clear"></div>
                         break;
                     case RendererType.TextBox:
                         <div class="form-row">
                             <span class="label">@descriptor.LabelResourceKey:</span>
                             @Html.TextBox(descriptor.Name, descriptor.TextValue)
                         </div>
                         <div class="clear"></div>
                         break;
                     case RendererType.TextArea:
                         <div class="form-row">
                             <span class="label">@descriptor.LabelResourceKey:</span>
                             @Html.TextArea(descriptor.Name, descriptor.TextValue)
                         </div>
                         <div class="clear"></div>
                         break;
                     case RendererType.DropDown:
                         <div class="form-row">
                             <span class="label">@descriptor.LabelResourceKey:</span>
                             @Html.DropDownList(descriptor.Name, descriptor.Items)
                         </div>
                         <div class="clear"></div>
                         break;
                     case RendererType.Image:
                         <div class="form-row photo-row">
                             <span class="label"></span>
                             @if (descriptor.ImageValue != null)
                             {
                                 <a class="lightbox" href="@PathHelper.PhotoPathForWeb(descriptor.ImageValue.AlbumId, descriptor.ImageValue.PhotoId, descriptor.ImageValue.Version)">
                                    <img class="photo" src="@PathHelper.PhotoThumbPathForWeb(descriptor.ImageValue.AlbumId, descriptor.ImageValue.PhotoId, descriptor.ImageValue.Version)" alt=""/>
                                 </a>
                             }
                         </div>
                         <div class="clear"></div>
                         break;
                     case RendererType.File:
                         <div class="form-row file-row">
                             <span class="label">@descriptor.LabelResourceKey:</span>
                             <span style="display: none;" class="file-name"></span> 
                             <a href="#" class="file-link hoverable">Zmień</a>
                             <input class="file-input" style="display: none;" type="file" name="@descriptor.Name" />
                         </div>
                         <div class="clear"></div>
                         break;
                 }
             }
         
             <input class="submit-button" type="submit" value="Save"/>
             <a class="hoverable" href="@Url.Action("List", Model.ControllerName, new { area = "Admin"})">Cancel</a>
        </div>
     }
}